package org.hdl.anima.message;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.hdl.anima.common.io.Index;
import org.hdl.anima.common.io.InputArchive;
import org.hdl.anima.common.io.OutputArchive;
import org.hdl.anima.common.io.Record;

/**
 * 
 * @author qiuhd
 * @since  2014年8月15日
 */
public class Receivers implements Record {
	
	private List<Integer> receivers;
	
	public Receivers() {
	}
	
	public Receivers(List<Integer> receivers) {
		this.receivers = receivers;
	}
	
	@Override
	public void serialize(OutputArchive archive) throws IOException {
		archive.startVector(receivers);
		if (receivers != null) {
			for (int receiver : receivers) {
				archive.writeInt(receiver);
			}
		}
	}

	@Override
	public void deserialize(InputArchive archive) throws IOException {
		Index id = archive.startVector();
		if (id != null) {
			receivers = new ArrayList<Integer>(id.size());
			if (!id.done()) {
				int r = archive.readInt();
				receivers.add(r);
				id.incr();
			}
		}
	}

	public List<Integer> getReceivers() {
		return receivers;
	}

	public void setReceivers(List<Integer> receivers) {
		this.receivers = receivers;
	}
}

